#ifndef CLIENT_NETWORK_H
#define CLIENT_NETWORK_H
#include<QTcpSocket>
#include<QObject>
#include"message_util.h"

class ClientNetwork:public QObject{
    Q_OBJECT
public:
    explicit ClientNetwork(QObject *parent =nullptr);
    ~ClientNetwork();
    void connectToServer(const QString &host,quint16 port);
    void sendMessage(const QByteArray &data);

signals:
    void newMessageReceived(const QByteArray &data);
    void loginResponseReceived(const QJsonObject &data);
    void registerResponseReceived(const QJsonObject &data);
    void privateMessageReceived(const QJsonObject &data);
    void groupMessageReceived(const QJsonObject &data);
    void onlineUsersUpdated(const QJsonArray &users);
    void imageTransferReceived(const QJsonObject &data);
    void fileTransferReceived(const QJsonObject &data);
    void rawDataReceived(QTcpSocket *socket, const QByteArray &data);
private slots:
    void onReadyRead(QTcpSocket *socket, const QByteArray &data);

private:
    QTcpSocket *socket;
    QMap<QTcpSocket*, QByteArray> bufferMap; // 新增的 bufferMap 声明
};

#endif // CLIENT_NETWORK_H
